<?php
/* TODO: Add code here */
require('config/globalconfig.php');
?>
<?php

include_once('classes/user_section.php');
//user_common::writeLog('insert',0);

$objsection = new user_section($objConnection);
if ($_pgR["act"]==user_section::ACT_ADD)
{
	if (user_common::isCLogin())
	{
		//lấy thông tin user
		//$c_userInfo = $_SESSION[consts::SES_C_USERINFO];
		
		
		$strName = $_pgR['name'];
		$strDetail= $_pgR['detail'];
		$resultID = $objsection->insert($strName,$strDetail);
		if ($resultID)
		{
			$arrHeader = user_common::getMessageHeaderArr($banCode);//$banCode
			//echo $strHeaderMessage."1".consts::SEP_RESPONSE.$strResultHTML.consts::SEP_RETURN.$_pgR["ontop"];
			echo user_common::convertToXML(
					$arrHeader, array("rs", "inf"), 
					array(1, $result ), 
					array( 0, 1 )
					);
			return;
		}
		else
		{
			echo user_common::convertToXML($arrHeader, array("rs"), array(0), array(0));
			return;
		}
	}
	else
	{
		echo user_common::convertToXML($arrHeader, array("rs",'info'), array(0,user_common::STRING_REQUIRE_LOGIN), array(0,1));
	}
	
	return;
}
elseif($_pgR['act'] == user_section::ACT_UPDATE)
{
	if (user_common::isCLogin())
	{
		//lấy thông tin user
		//$c_userInfo = $_SESSION[consts::SES_C_USERINFO];
		
		$strID = $_pgR['id'];
		$strName = $_pgR['name'];
		$strDetail= $_pgR['detail'];
		$resultID = $objsection->update($strID,$strName,$strDetail);
		if ($resultID)
		{
			$arrHeader = user_common::getMessageHeaderArr($banCode);//$banCode
			//echo $strHeaderMessage."1".consts::SEP_RESPONSE.$strResultHTML.consts::SEP_RETURN.$_pgR["ontop"];
			echo user_common::convertToXML(
					$arrHeader, array("rs", "inf"), 
					array(1, $result ), 
					array( 0, 1 )
					);
			return;
		}
		else
		{
			echo user_common::convertToXML($arrHeader, array("rs"), array(0), array(0));
			return;
		}
	}
	echo user_common::convertToXML($arrHeader, array("rs"), array(0), array(0));
	return;
}
elseif($_pgR['act'] == user_section::ACT_CHANGE_PAGE)
{
	$intPage = $_pgR['p'];
	
	$outPutHTML =  $objsection->getListsection($intPage);
	echo user_common::convertToXML($strMessageHeader, array('rs','inf'), array(1,$outPutHTML),array(0,1));
	return ;
}
elseif($_pgR['act'] == user_section::ACT_SHOW_EDIT)
{
	
	$section_id = $_pgR['id'];
	$arrsection =  $objsection->getsectionByID($section_id);
	echo user_common::convertToXML($strMessageHeader, array('rs','id','name','detail'), array(1,$arrsection['section_id'],$arrsection['name'],$arrsection['detail']),array(0,1,1,1));
	return ;
}

?>



<?php
include_once('include/_header.inc');
include_once('include/_menu.inc');
?>
<script type="text/javascript" src="<?php echo $_objSystem->locateJs('user_section.js');?>"></script>
	
<!--Begin Form Input -->
<input type="hidden" id="adddocmode" name="adddocmode" value="1<?php //echo $intMode;?>" />
<input type="hidden" id="txtPage" name="txtPage" value="<?php echo $_pgR["p"]?$intPage:1;?>" />
<input type="hidden" id="txtID" name="txtID" value="" />
 <center>
<br><h2 align="center">Quản lý ngành hàng</h2>
		<div class="input-field-border input-field-content" >
				<div id="lgTitle" class="div_admin_group_title" style="">
				<span style="cursor:default; font-family:inherit" id='status-add' name='status-add'>Add Mode</span></div>
				
				<div class="div_admin_group_content_inside" style="width: 100%; top: -20px;">
				  <table id="tblPopUp" style="width: 100%;" border="0" cellpadding="2" cellspacing="0">
				  <tbody>
									  
				  <tr>
					<td width="110"><span style="cursor:default; font-family:inherit">Tên ngành hàng </span></td>
					<td width="567"><input id="txtName" name="txtName" value="" style="width: 49.5%;"  maxlength="255" type="text"></td>
				  </tr>
				 
				 <tr>
					<td width="110"><span style="cursor:default; font-family:inherit">Chi tiết </span></td>
					<td width="567"><input id="txtDetail" name="txtDetail" value="" style="width: 49.5%;"  maxlength="255" type="text"></td>
				  </tr>
				</tbody></table>
				</div>
	

				<div class="div_admin_group_content_inside" style="margin: 4px; display: block;" align="center">		
				  <input id="btnOK" value="OK"  style="width: 50px;" onClick="_objsection.btnSave_OnClick()" type="button" class="btn btn-oliver"> &nbsp;&nbsp;&nbsp;
				  <input id="btnClose" value="Cancel" align="center" style="width: 55px;" onClick="_objsection.showAddMode()" type="button" class="btn btn-oliver">  
			  </div>					
		</div>	
	
		</center>
<!--End Form Input -->

   <div  id="content-admin" >
                    <div align="center">
	                    <h2>Danh sách</h2>									
					</div>
					<div id="list-content" style="padding:10px">
						<?php echo $objsection->getListsection(1) ?>					
						</div>
	</div>

<?php 
//footer
include_once('include/_footer.inc');
?>